<template>
  <div class="" v-loading="loading">
    <div style="margin: 20px 0;">
      <el-input placeholder="请输入资讯名称进行搜索" v-model="keywords" class="input-with-select" @keyup.enter.native="loadMore()">
        <el-button slot="append" icon="el-icon-search" @click="loadMore()"></el-button>
      </el-input>
    </div>
    <el-tabs v-model="enterpriseName" @tab-click="handleClick"
    class="self-tab-style"  element-loading-text="拼命加载中">
      <!-- <el-tab-pane label="综合" name="">
        <enterprise-list @selected-enter="openDetails" :datas="data"></enterprise-list>
      </el-tab-pane> -->
      <el-tab-pane label="通知公告" name="134A9C15597F11E892D5A46C2A38CB5E">
        <enterprise-list @selected-enter="openDetails" :datas="data"></enterprise-list>
      </el-tab-pane>
      <el-tab-pane label="协会动态" name="1FD5A57D597F11E892D5A46C2A38CB5E">
        <enterprise-list @selected-enter="openDetails" :datas="data"></enterprise-list>
      </el-tab-pane>
      <el-tab-pane label="产业新闻" name="24C1306A597F11E892D5A46C2A38CB5E">
        <enterprise-list @selected-enter="openDetails" :datas="data"></enterprise-list>
      </el-tab-pane>
      <el-tab-pane label="会员新闻" name="29A9C63B597F11E892D5A46C2A38CB5E">
        <enterprise-list @selected-enter="openDetails" :datas="data"></enterprise-list>
      </el-tab-pane>
      <el-tab-pane label="会员活动" name="2F462874597F11E892D5A46C2A38CB5E">
        <enterprise-list @selected-enter="openDetails" :datas="data"></enterprise-list>
      </el-tab-pane>
    </el-tabs>
    <el-button type="success fr width-200" style="margin-top: 20px;" plain round  @click="loadMore()"
      v-show="hasMore">查看更多</el-button>
  </div>
</template>

<script>
import axios from 'axios'
import EnterpriseList from '../home/EnterpriseList'
export default {
  components: {
    EnterpriseList
  },
  title: '咨询列表',
  name: 'advisory-list',
  data () {
    return {
      loading: false,
      keywords: '', // 关键字
      oldKeywords: '',
      enterpriseName: '134A9C15597F11E892D5A46C2A38CB5E',
      pageIndex: 0, // 页码
      limit: 10, // 一页多少行数据
      type:'', // 那种类型咨询
      data: [],
      hasMore: true // 是否还有更多的数据
    }
  },
  props: {},
  mounted () {
    this.loadData()
  },
  methods: {
    loadMore () {
      this.pageIndex = this.pageIndex + 1
      this.loadData()
    },
    handleClick (key, path) {
      this.hasMore = true
      this.pageIndex = 0
      this.loadData()
    },
    openDetails (data) {
      gtag('event', '点击', {
        'event_category': '查看详情',
        'event_label': data.basicTitle,
        'value': 0
      });
      const {href} = this.$router.resolve({
        name: 'eventdetails',
        query: {id: data.modelId || data.informationId, basicType: data.basicType, browseNumber: data.browseNumber, comments: data.comments}
      })
      window.open(href, '_blank')
    },
    serarchKeywords () {
      this.loading = true
      let params = {
        offset: this.pageIndex * this.limit,
        limit: this.limit,
        type: this.enterpriseName,
        search: this.keywords
      }
      let url = '/mscs/information/findInformationBasicByType'
      if (this.enterpriseName === '2F462874597F11E892D5A46C2A38CB5E') {
        url = '/mscs/activity/findActivityBasic' // 查询活动为单独的接口
      }
      axios.post(url, this.$paramsConvert(params)).then((res) => {
        if (this.pageIndex === 0) {
          this.data = res.data.data
        } else {
          this.data.push(...res.data.data)
        }
        if (res.data.data.length < this.limit) {
          this.hasMore = false
        }

      }).catch((error) => {
        this.$catchError(error)
      }).finally(() => {
        this.loading = false
      })
    },
    loadData () {
      this.loading = true
      // 如果本次的关键字不是上一次的关键字，则将设置为首页
      if (this.keywords !== this.oldKeywords) {
        this.pageIndex = 0
        this.oldKeywords = this.keywords
      }
      let params = {
        offset: this.pageIndex * this.limit,
        limit: this.limit,
        type: this.enterpriseName,
        search: this.keywords
      }
      let url = '/mscs/information/findInformationBasicByType'
      if (this.enterpriseName === '2F462874597F11E892D5A46C2A38CB5E') {
        url = '/mscs/activity/findActivityBasic' // 查询活动为单独的接口
      }
      axios.post(url, this.$paramsConvert(params)).then((res) => {
        if (this.pageIndex === 0) {
          this.data = res.data.data
        } else {
          this.data.push(...res.data.data)
        }
        if (res.data.data.length < this.limit) {
          this.hasMore = false
        }

      }).catch((error) => {
        this.$catchError(error)
      }).finally(() => {
        this.loading = false
      })
    },
    // 自动选中活动
    autoSelect () {
      this.enterpriseName = '2F462874597F11E892D5A46C2A38CB5E'
      this.handleClick()
    }
  }
}
</script>
